home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 5
/
Gekikoh Dennoh Club Vol. 5 (Japan).7z
/
Gekikoh Dennoh Club Vol. 5 (Japan) (Track 01).bin
/
internet
/
tcppack
/
tcppackb.lzh
/
src
/
samples
/
finger.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-03
|
2KB
|
93 lines
#include<stdio.h>
#include<string.h>
#include"network.h"
#include"socket.h"
static void finger (char *, char *);
void
main (int argc, char **argv)
{
int i;
for (i = 1; i < argc; i++)
{
char *user, *target;
target = strchr (argv[i], '@');
if (target)
{
user = argv[i];
*target++ = '\0';
finger (target, user);
}
}
return;
}
static void
finger (char *target, char *user)
{
long ipaddr;
struct hostent *h;
char buff[256];
int sock, len, port;
struct sockaddr_in fsocket;
struct servent *s;
s = getservbyname ("finger", "tcp");
if (!s)
{
fprintf (stderr, "finger: No finger service on this host\n");
return;
}
port = s->s_port;
h = gethostbyname (target);
if (!h)
{
fprintf (stderr, "Host name look up failure: %s\n", target);
return;
}
ipaddr = *(long*)h->h_addr;
fsocket.sin_family = AF_INET;
fsocket.sin_port = port;
fsocket.sin_addr.s_addr = ipaddr;
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock == -1)
{
fprintf (stderr, "Can't create socket\n");
return;
}
if (connect (sock, (char *)&fsocket, sizeof (struct sockaddr_in)) == -1)
{
fprintf (stderr, "Unable to connect: %s\r\n", sockerr (sock));
return;
}
write_s (sock, user, strlen (user));
write_s (sock, "\r\n", 2);
for (;;)
{
len = socklen (sock, 0);
if (len < 0)
break;
if (len)
{
len = read_s (sock, buff, len < sizeof (buff) ? len : sizeof (buff));
if (len > 0)
{
buff[len] = '\0';
write (fileno (stdout), buff, len);
}
}
}
close_s (sock);
}